package com.qyhl.module_activities.act.signup;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import androidx.annotation.NonNull;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;

import com.qyhl.module_activities.R;
import com.qyhl.webtv.basiclib.utils.StringUtils;


/**
 * Created by Administrator on 2018/3/16.
 */

public class ChangeNameDialog extends Dialog {
    private View view;
    private ChangeNameListener listener;

    public void setListener(ChangeNameListener listener) {
        this.listener = listener;
    }

    public ChangeNameDialog(@NonNull Context context) {
        this(context, 0);
    }

    public ChangeNameDialog(@NonNull Context context, int themeResId) {
        super(context, R.style.act_BaseDialogStyle);
        view = LayoutInflater.from(context).inflate(R.layout.act_change_work_name_dialog, null);
        init();
    }

    private void init() {
        view.findViewById(R.id.cancle).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        final EditText editText = (EditText) view.findViewById(R.id.work_name);
        Button ok = (Button) view.findViewById(R.id.ok);

        ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String text = editText.getText().toString();
                if (!TextUtils.isEmpty(text)) {
                    listener.changeName(text);
                }
                dismiss();
            }
        });
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(view);

        Window win = getWindow();
        assert win != null;
        WindowManager.LayoutParams lp = win.getAttributes();
        lp.width = StringUtils.dip2px(getContext(), 300);
        lp.height = StringUtils.dip2px(getContext(), 151);
        win.setAttributes(lp);
    }

    interface ChangeNameListener {
        void changeName(String name);
    }
}

